{extend name="ashippingmanagement3/Public/base" /}
{block name="container"}
<style>
    .error{
        color:red;
    }
     .checkbox-inline input[type=checkbox],.radio-inline input[type=radio] {
         margin-top: 4px;
     }
</style>
<script>
    $(function (){
        $('#uploadify').uploadifive({
            'buttonText': '附件',
            'width': '50px',
            'height': '30px',
            'fileObjName':"bx_wd",
            'queueID':"uploadifyQueue",
            'queueSizeLimit': 15,//这里我只允许单个图片上传
            'uploadScript':'{:url("ashippingmanagement2/uploadifive")}',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.success) {
                    var dataValue = JSON.stringify(data.data);
                    file.queueItem.attr('uri',dataValue);
                }else {
                    file.queueItem.addClass('error');
                    file.queueItem.find('.fileinfo').html('-'+data.message);
                }
            }
        });
    })
</script>
<!-- 标题 -->
<div class="page-heade">
    <h1 class="title_color">新增网点零售数据</h1>
</div>
<!-- 标题 -->
<div>
    <form id="form_id" action="" class="form-inline" method="post">
        <table class="row-margin-top tab-content table-bordered table text-left" border="1">
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">日期<span class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control layer-date validate[required,custom[date]]" name="wdDate" id="netDate"></td>
            </tr>
            <tr>
                <td style="min-width: 140px;width: 140px" class="text-right"><label for="" class="form-label">网点名称<span class="colorRed">*</span>：</label></td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group" id="NetDiv">
                            <input type="text" class="form-control validate[required]" value="" name="wd" id="wd"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="wd_id" id="wd_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="select_net" value="选择"/>
                    </div>

                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">产品名称<span class="colorRed">*</span>：</label></td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control validate[required]" value="" name="cp" id="cp"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="cp_id" id="cp_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectCp" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">单位<span class="colorRed">*</span>：</label></td>
                <td>
                    <input type="text" class="form-control validate[required]" readonly name="dw" id="dw" value="">
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">单价<span class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control validate[required,custom[number]]" name="dj" id="dj" value=""></td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">数量<span class="colorRed">*</span>：</label></td>
                <td><input type="text" class="form-control validate[required,custom[integer]]" name="num" value="">注：退货可录入负数。</td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">金额(元)<span class="colorRed">*</span>：</label></td>
                <td>
                    <input type="text" class="form-control validate[required,custom[number]]" name="money" value="">
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">导购人员：</label></td>
                <td>
                    <div class="col-xs-4">
                        <div class="input-group">
                            <input type="text" class="form-control" value="" name="dgUser" id="dgUser"
                                   placeholder="请输入关键字或空格查询">
                            <div class="input-group-btn">
                                <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="dgUser_id" id="dgUser_id" value="">
                    <div class="col-xs-2">
                        <input type="button" class="btn btn-primary" id="selectDgUser" value="选择"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right"><label for="" class="form-label">批号/批次：</label></td>
                <td><input type="text" class="form-control" name="phpc" value=""></td>
            </tr>
            <tr>
                <td style="min-width: 140px" class="text-right" rowspan="2"><label for="" class="form-label">备注：</label></td>
                <td>
                    <textarea name="des" id="des" class="form-control validate[maxSize[100]] rows="2" style="user-select:none;width: 70%"></textarea><span style="vertical-align: bottom;">100</span>
                </td>
            </tr>
        </table>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px" id="upfileDiv">
                <!--<input type="file" id="exampleInputFile" name="exampleInputFile">-->
                <input type="button" name="uploadify" id="uploadify">
                <div id="uploadifyQueue"></div>
                <p class="help-block" style="color:#1295d2">注：最多上传15个文件，每个文件小于50M,支持格式：</p>
                <p class="help-block" style="color:#1295d2">
                    jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav</p>
        </div>
        <div class="text-center">
            <button class="btn btn-info" type="button" onclick="submits(1);">保存并再添加一条</button><span class="lr_5"></span>
            <button class="btn btn-success" type="button" onclick="submits(2);">保存并返回</button><span class="lr_5"></span>
            <button class="btn btn-warning" type="button" onclick="back()">返回</button>
        </div>
    </form>
</div>
<script>
    laydate({
        elem:"#netDate",
        event:"focus"
    })
    //表单验证
    $('#form_id').validationEngine('attach', {
        promptPosition: 'bottomRight'
    });
    function submits(type){
        if($('#form_id').validationEngine('validate')){
            var enclosure_url = '';
            $('form').find('#uploadifyQueue .uploadifive-queue-item').each(function(){
                if($(this).attr('uri')){
                    if(enclosure_url==''){
                        enclosure_url+=$(this).attr('uri');
                    }else {
                        enclosure_url+="||"+$(this).attr('uri');
                    }
                }
            });
            $.post("{:url('Ashippingmanagement3/add')}",$('form').serialize()+'&file='+enclosure_url,function(re){
                if(re.success){
                    if(type == 1){
                        swal({title: '添加成功，继续添加！', text: '', type: "success"});
                    }else{
                        back();
                    }
                }else{
                    swal({title: re.msg, text: '', type: "warning"});
                }
            },'json')
        }
    }
    //弹出选择网点框
    $('#select_net').on('click',function () {
        var index = layer.getFrameIndex(window.name)
        layer.open({
            type:2,
            area:['60%','60%'],
            maxmin:true,
            content:'/index/Ashippingmanagement3/selectnet.html?index='+index
        })
        return  false
    })

    //网点补全
    $("#wd").bsSuggest({
        url: "{:url('select/netjson2')}",
        effectiveFieldsAlias: {title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, re) {
        $('#wd').val(re.key);
        $('#wd_id').val(re.id);
    });
    //产品单品搜索自动补全
    $("#cp").bsSuggest({
        url: "/index.php/index/select/productjson",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $('#cp').val(keyword.key);
        $('#cp_id').val(keyword.id);
        unit(keyword.id);//根据产品id带出单位
    });
    //弹出选择产品树状
    $('#selectCp').on('click',function () {
        layer.open({
            type:2,
            area:['60%','80%'],
            maxmin:true,
            content:'{:url("Ashippingmanagement/selectProduct")}',
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents();
                var id =  a.find("#renyuan").val();
                var name =  a.find("#renyuanname").val();
                if(id){
                    $('#cp').val(name);
                    $('#cp_id').val(id);
                    unit(id);//根据产品id带出单位
                }
                layer.close(i);
            }
        });
        return  false
    });
    //根据产品id带出单位
    function unit(id){
        $.get('{:url("Ashippingmanagement3/cpUnit")}',{id:id},function (data){
            if(data.success){
                $('#dw').val(data.unit);
            }
        });
    }
    //销售人员搜索自动补全
    $("#dgUser").bsSuggest({
        url: "/index.php/index/apcaiwu/cnamejson",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        console.log(keyword);
        $('#dgUser').val(keyword.key);
        $('#dgUser_id').val(keyword.id);
    });
    //弹出选择销售人树
    $('#selectDgUser').click(function (){
        layer.open({
            type:2,
            area:['60%','60%'],
            title:'导购人员',
            maxmin:true,
            content:'/index.php/index/apcaiwu/selectCname',
            btn:['确定','关闭'],
            btnAlign:'c',
            yes:function (i,o) {
                var id = $(o).find('iframe').contents().find('#renyuan').val()
                var name = $(o).find('iframe').contents().find('#renyuanname').val()
                if(id){
                    $('#dgUser').val(name);
                    $('#dgUser_id').val(id);
                }
                layer.close(i)
            }
        });
        return  false
    });
</script>
{/block}
